package com.ruoyi.web.controller.wechatApplet;

import com.ruoyi.background.domain.AppActivityShow;
import com.ruoyi.background.service.IAppActivityShowReadService;
import com.ruoyi.background.service.IAppActivityShowService;
import com.ruoyi.background.utils.SYS_CONSTANT;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/wechat/show")
public class ShowController extends BaseController {

    @Autowired
    private IAppActivityShowService appActivityShowService;

    @Autowired
    private IAppActivityShowReadService appActivityShowReadService;

    @Autowired
    private RedisCache redisCache;

    /**
     * 查询活动风采列表
     *
     * @param activityShow 查询条件
     * @return list
     */
    @GetMapping("/getList")
    public TableDataInfo getShowList(AppActivityShow activityShow) {
//        String key = REDIS_KEY.SHOW_LIST_KEY;
//        List<AppActivityShow> showList = redisCache.getCacheList(key);
//        if (ObjectUtils.isEmpty(showList)) {
//            activityShow.setStatus(0);
//            showList = appActivityShowService.getWechatActivityShowList(activityShow);
//            redisCache.deleteByKey(key);
//            redisCache.setCacheList(key, showList);
//            redisCache.expire(key, 2 * 60, TimeUnit.MINUTES);
//        }
        return getDataTable(SYS_CONSTANT.SHOW_LIST_CONS);
    }

    /**
     * 通过Id获取详情
     *
     * @param id id
     * @return 结果
     */
    @GetMapping("/get/{id}")
    public AjaxResult getShowById(@PathVariable Long id) {
        AppActivityShow show = appActivityShowService.selectAppActivityShowById(id);
        if (1 == show.getDelFlag()) return AjaxResult.error("规章制度已删除！");
        if (1 == show.getStatus()) return AjaxResult.error("规章制度已下架");
        appActivityShowReadService.setActivityRead(SecurityUtils.getUserId(), SecurityUtils.getDeptId(), show.getId());
        return AjaxResult.success(show);

    }

}
